package com.dnjn.mes.biz.mapper;

import com.dnjn.mes.biz.domain.MesWorkforceShiftClocking;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * <p>
 * 打卡记录 Mapper 接口
 * </p>
 *
 * @author Amber
 * @since 2023-08-29
 */
public interface MesWorkforceShiftClockingMapper extends BaseMapper<MesWorkforceShiftClocking> {

    @Select(" SELECT * FROM mes_workforce_shift_clocking WHERE equipment_id=#{equipmentId} AND user_id=#{userId} AND shift_id = #{shiftId} ")
    MesWorkforceShiftClocking checkClockInOrOut(@Param("equipmentId")long equipmentId, @Param("userId")Long userId,@Param("shiftId")Long shiftId);

    @Select(" SELECT * FROM mes_workforce_shift_clocking WHERE equipment_id=#{equipmentId} AND user_id=#{userId} AND DATE_FORMAT(create_time,'%Y-%m-%d') = #{date} ")
    MesWorkforceShiftClocking checkClockUser(@Param("date") String date, @Param("equipmentId")long equipmentId, @Param("userId")Long userId);

    @Update(" UPDATE mes_workforce_shift_clocking SET has_clockout='1',clockout_datetime=NOW() WHERE shift_id=#{shiftId}")
    void checkOutAll(@Param("shiftId")Long shiftId,@Param("equipmentId") long equipmentId);

    List<MesWorkforceShiftClocking> clockInRecords(@Param("searchKey")String searchKey, @Param("equipmentId")long equipmentId);

}
